using System.Diagnostics;
using Microsoft.Win32;
using TXLooker.Common.Outlook;
using TXLooker.WorkItemExtention.Properties;

namespace TXLooker.WorkItemExtention.Core
{
    public class ColorPattern
    {        
        private RegistryKey m_regKey = Registry.CurrentUser.CreateSubKey(Resources.REGISTRY_COLORCATEGORIES_PATH);
        private string m_projectName;
        private string m_workItemTypeName;
        private string m_state;
       
        protected ColorPattern()
        {}
        public ColorPattern(string projectName, string workItemTypeName, string state)
            : this()
        {
            this.m_projectName = projectName;
            this.m_workItemTypeName = workItemTypeName;
            this.m_state = state;           
        }
      
        public void Save(string colorCategory)
        {
            Debug.Assert(!string.IsNullOrEmpty(colorCategory),"m_colorCategory is empty");
            string saveString = string.Format("{0}", colorCategory);
            string saveName = string.Format("{0};{1};{2};", this.m_projectName, this.m_workItemTypeName, this.m_state);
            m_regKey.SetValue(saveName, saveString);              
        }

        public string Load(Microsoft.Office.Interop.Outlook.Application app)
        {
           
             string loadString = string.Format("{0};{1};{2};",m_projectName,m_workItemTypeName,m_state);
             string colorCategory = m_regKey.GetValue(loadString,string.Empty) as string;
             if (!string.IsNullOrEmpty(colorCategory))
             {
                 return colorCategory;
             }
             else
             {
                 return OutlookGlobal.GetDefaultCategory(app);
             }
        }            
    }
}